/*
 * 
 * Created on Jul 12, 2005
 */
package com.wgo.precise.client.ui.view.util.contentproviders;

import java.util.Collection;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.wgo.precise.client.ui.model.facade.INodeChild;
import com.wgo.precise.client.ui.model.facade.INodeParent;


/**
 * @author Petter L. H. Eide
 * @version $Id: ModelTreeViewContentProvider.java,v 1.2 2006-01-30 21:52:32 petterei Exp $
 */
public class ModelTreeViewContentProvider implements IStructuredContentProvider, ITreeContentProvider {

//	private static ViewerFilter[] filters = new ViewerFilter[] {new ProjectViewerFilter(), new StakeholderViewerFilter(), new PropertyDefinitionSetViewFilter()} ;
	
	@SuppressWarnings("unused")
	public void inputChanged(Viewer v, Object oldInput, Object newInput) {/* not in use */}
	
	public void dispose() {/* not in use */}
	
	public Object[] getElements(Object parent) {
		if (parent instanceof Object[]) {
			return (Object[])parent;
		}
		return getChildren(parent);
	}
	@SuppressWarnings("unchecked")
	public Object getParent(Object child) {
		if (child instanceof INodeChild) {
			return ((INodeChild)child).getParent();
		} 
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public Object [] getChildren(Object parent) {
		if (parent instanceof Object[]) {
			return (Object[])parent;
//		} else if (parent instanceof ProjectRootSystemWrapper) {
//			Object[] children = ((ProjectRootSystemWrapper)parent).getChildren().toArray(); //TODO: type safety
//			TreeViewFolder[] folders = new TreeViewFolder[filters.length];
//			for (int i = 0; i<filters.length; i++) {
//				folders[i] = new TreeViewFolder(filters[i].filter(null, null, children));
//			}
//			return folders;
		} else if (parent instanceof INodeParent) {
			Collection<INodeChild> l = ((INodeParent)parent).getChildren();
			return l.toArray(new INodeChild[l.size()]);
		} 
//		else if (parent instanceof TreeViewFolder) {
//			return ((TreeViewFolder)parent).children;
//		}
		return new Object[0];
	}
	
	@SuppressWarnings("unchecked")
	public boolean hasChildren(Object parent) {
		if (parent instanceof INodeParent) {
			return ((INodeParent)parent).hasChildren();
		}
//		else if (parent instanceof TreeViewFolder)
		return false;
	}
	
//	class TreeViewFolder implements ILabelProviderItem {
//		Object[] children; // TODO: type safety
//		TreeViewFolder(Object[] children) {
//			this.children = children;
//		}
//		public Image getImage() {
//			return null;
//		}
//		public String getSimpleName() {
//			return "simpleName";
//		}
//		public String getText() {
//			return "text";
//		}
//		public String getToolTipText() {
//			return null;
//		}
//		
//	}
}

/**
 * Changelog:
 * 
 * $Log: ModelTreeViewContentProvider.java,v $
 * Revision 1.2  2006-01-30 21:52:32  petterei
 * implemented wrapper factory and lazy wrapper-instantiation of parents
 * implemented a "system" for each top-node type
 * added top-categories for all top-nodes
 * implemented some interfaces for the wrappers, and started using these
 *
 * Revision 1.1  2006-01-23 19:58:38  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.1  2006-01-13 08:13:20  petterei
 * Using Long consequently to differentiate between �null� and �0� for dbId and conceptId (no boxing/unboxing)
 * Ajusted code to stronger java-syntax
 *
 * Revision 1.4  2005-12-14 08:22:04  petterei
 * -refactored: new categories inherit propertysets from parent category, requirements-propertysets is only retrieved from parent category (before: no "physical" category inheritance, but requirement got propertysets from all categoryparents)
 * -cleaned up some code and configfiles, minor refactoring
 *
 * Revision 1.3  2005-12-08 20:36:57  petterei
 * added gui to assign propertydefinitionsets to categories
 *
 * Revision 1.2  2005-12-08 14:51:22  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005-12-07 07:25:35  petterei
 * gui & logic for relationships
 *
 * Revision 1.5  2005-11-22 13:56:53  petterei
 * *** empty log message ***
 *
 * Revision 1.4  2005/11/21 15:40:45  petterei
 * *** empty log message ***
 *
 * Revision 1.3  2005/09/29 16:41:42  petterei
 * *** empty log message ***
 *
 * Revision 1.2  2005/09/27 21:06:18  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/09/27 17:04:29  petterei
 * inittial commit
 *
 */
